package vmo;

import java.net.InetAddress;
import java.net.UnknownHostException;

import client.MainScene;
import network.Client;
import network.Packet;
import network.Packet_Message;
import network.Packet_Player;
import server.Server;
import shared.MouseHook;
import shared.Scene;

public class Jumpstarter implements Scene {
	
	Client m_client;
	int [] m_variables;
	public Jumpstarter(int [] variables)
	{
		m_variables=variables;
		//start server
		Game.g_server=new Server();
		Game.g_serverthread=new Thread(Game.g_server);
		Game.g_serverthread.start();	
		//start client
		m_client=new Client();		
		//have client initiate connection with server
		try {
			m_client.Connect(InetAddress.getByName("localhost"),"nullhandle",new byte[]{0,10,6,2});
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
	}
	
	@Override
	public void Update(float dt) {
		// TODO Auto-generated method stub
		m_client.Update(dt);
		ReadClient();		
	}

	@Override
	public void Draw() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void Start(MouseHook mouse) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void End() {
		// TODO Auto-generated method stub
		
	}

	public void ReadClient()
	{
		Packet p=m_client.getPacket();
		if (p!=null)
		{
			String str="client ";
			//read packet, especially if it's a handshake
			switch (p.getType())
			{

				case PLAYER:

				//transition to next scene
				Client ci=m_client; m_client=null;
				
				Game.g_manager.SwapScene(new MainScene(ci,m_variables,(Packet_Player)p));
				
				break;

			
			}
		}
	}		
	
}
